package org.assertj.ohos.api.view;

import ohos.agp.components.DragEvent;
import org.assertj.core.api.AbstractAssert;
import static ohos.agp.components.DragEvent.*;
import static org.assertj.ohos.internal.BitmaskUtils.buildNamedValueString;
import static org.assertj.core.api.Assertions.assertThat;

/** Assertions for {@link DragEvent} instances. */
public class DragEventAssert extends AbstractAssert<DragEventAssert, DragEvent> {
  public DragEventAssert(DragEvent actual) {
    super(actual, DragEventAssert.class);
  }

  public DragEventAssert hasAction(int action) {
    isNotNull();
    int actualAction = actual.getAction();
    //noinspection ResourceType
    assertThat(actualAction) //
        .overridingErrorMessage("Expected action <%s> but was <%s>",
            dragEventActionToString(action), dragEventActionToString(actualAction)) //
        .isEqualTo(action);
    return this;
  }
/* // TODO: wang, not found in ohos
  public DragEventAssert hasLocalState(Object localState) {
    isNotNull();
    Object actualLocalState = actual.getLocalState();
    assertThat(actualLocalState) //
        .overridingErrorMessage("Expected local state <%s> but was <%s>", localState,
            actualLocalState) //
        .isEqualTo(localState);
    return this;
  }

  public DragEventAssert hasSuccessfulResult() {
    isNotNull();
    assertThat(actual.getResult()) //
        .overridingErrorMessage("Expected successful result but was unsuccessful") //
        .isTrue();
    return this;
  }

  public DragEventAssert hasUnsuccessfulResult() {
    isNotNull();
    assertThat(actual.getResult()) //
        .overridingErrorMessage("Expected unsuccessful result but was successful") //
        .isFalse();
    return this;
  }*/

  public DragEventAssert hasX(float x) {
    isNotNull();
    float actualX = actual.getX();
    assertThat(actualX) //
        .overridingErrorMessage("Expected X <%s> but was <%s>", x, actualX) //
        .isEqualTo(x);
    return this;
  }

  public DragEventAssert hasY(float y) {
    isNotNull();
    float actualY = actual.getY();
    assertThat(actualY) //
        .overridingErrorMessage("Expected Y <%s> but was <%s>", y, actualY) //
        .isEqualTo(y);
    return this;
  }

  public static String dragEventActionToString(int action) {
    return buildNamedValueString(action)
        .value(DRAG_FINISH, "drag finish")
        .value(DRAG_IN, "drag in")
        .value(DRAG_OUT, "drag out")
        .value(DRAG_MOVE, "drag move")
        .value(DRAG_BEGIN, "drag begin")
        .value(DRAG_DROP, "drop")
        .get();
  }
}
